import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MenuQuery, MenuForm } from "./types";

/**
 * 获取菜单树形列表
 *
 * @param queryParams
 */
export function listMenus(
  queryParams?: MenuQuery
): AxiosPromise<TreeResult<MenuForm>[]> {
  return getMenuOptions(queryParams);
}

/**
 * 获取菜单下拉树形列表
 */
export function getMenuOptions(
  queryParams?: MenuQuery
): AxiosPromise<TreeResult<MenuForm>[]> {
  return request({
    url: "admin/menu/tree",
    method: "get",
    params: queryParams,
  });
}

/**
 * 添加菜单
 *
 * @param data
 */
export function saveMenu(data: MenuForm) {
  return request({
    url: "admin/menu/save",
    method: "post",
    data,
  });
}

/**
 * 删除菜单
 *
 * @param id 菜单ID
 */
export function deleteMenu(ids: string[]) {
  return request({
    url: "admin/menu/del",
    method: "post",
    data: ids,
  });
}

/**
 * 生成按钮
 *
 * @param id 菜单ID
 */
export function createBtn(id: string) {
  return request({
    url: `admin/menu/btn/${id}`,
    method: "post",
  });
}
